package com.chenjf.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("test")
@RestController
public class TestController {

    /**
     * HystrixCommand : 表示出现异常错误达到一定条件后【注解实现断路】
     * fallbackMethod : 指定熔断时快速返回的方法
     *
     * @param id
     * @return
     */
    @HystrixCommand(fallbackMethod = "test2")
    @GetMapping("/test1/{id}")
    public String test1(@PathVariable Integer id) {
        if (id < 0) {
            throw new RuntimeException("不符合实际大小");
        }
        return "test1 ok! id=" + id;
    }

    public String test2(@PathVariable Integer id) {
        return "稍等一会会 ，马上就好";
    }
}
